package com.zhongge.binarytree;

/**
 * @ClassName TestMyBinaryTree
 * @Description TODO 测试自定义二叉树
 * @Author 笨忠
 * @Date 2025/8/30 17:08
 * @Version 1.0
 */
public class TestMyBinaryTree {
    public static void main(String[] args) {
        //手动创建二叉树
        MyBinaryTree tree = new MyBinaryTree();
        MyBinaryTree.TreeNode root = tree.createTree();


        System.out.print("前序遍历:");
        tree.preOrder(root);
        System.out.println();
        System.out.print("中序遍历:");
        tree.inOrder(root);
        System.out.println();
        System.out.print("后序遍历:");
        tree.postOrder(root);
        System.out.println();
        System.out.println("=====================");
        tree.size(root);
        System.out.println("节点个数：" + MyBinaryTree.nodeSize);
        System.out.println("节点个数：" + tree.size2(root));
        System.out.println("========================");
        tree.getLeafNodeCount1(root);
        System.out.println("叶子节点个数：" + MyBinaryTree.leafSize);
        System.out.println("叶子节点个数：" + tree.getLeafNodeCount2(root));
        System.out.println("=======================");
        System.out.println("第1层的节点个数：" + tree.getKLevelNodeCount(root, 1));
        System.out.println("第2层的节点个数：" + tree.getKLevelNodeCount(root, 2));
        System.out.println("第3层的节点个数：" + tree.getKLevelNodeCount(root, 3));
        System.out.println("第4层的节点个数：" + tree.getKLevelNodeCount(root, 4));
        System.out.println("===================");
        System.out.println("数的高度" + tree.getHeight(root));
        System.out.println("=====================");
        MyBinaryTree.TreeNode node1 = tree.find(root, 'A');
        System.out.println("查找元素：" + (node1 == null ? "没有这个值" : node1.val));

        MyBinaryTree.TreeNode node2 = tree.find(root, 'i');
        System.out.println("查找元素：" + (node2 == null ? "没有这个值" : node2.val));

        MyBinaryTree.TreeNode node3 = tree.find(root, 'c');
        System.out.println("查找元素：" + (node3 == null ? "没有这个值" : node3.val));
        System.out.println("=====================");
        System.out.print("层序遍历：");
        tree.levelOrder(root);
        System.out.println("================");
        System.out.println("判断二叉树是不是完全二叉树: " + tree.isCompleteTree(root));

    }
}
